package global

import (
	"database/sql"

	_ "github.com/mattn/go-sqlite3"
)

var DB *sql.DB

func InitDB() (err error) {
	DB, err = sql.Open("sqlite3", "./your-tool.db")
	if err != nil {
		panic(err)
	}

	// 新建表
	sql := `
	CREATE TABLE IF NOT EXISTS "acg" (
		"id" INTEGER PRIMARY KEY AUTOINCREMENT,
		"name" varchar(255) NOT NULL DEFAULT '',
		"search_name" varchar(255) NOT NULL DEFAULT '',
		"week" varchar(255) NOT NULL DEFAULT '',
		"level" INTEGER NOT NULL DEFAULT 1,
		"status" INTEGER NOT NULL DEFAULT 1 ,
		"create_time" DATE NOT NULL DEFAULT NULL,
		"update_time" DATE NOT NULL DEFAULT NULL
	  );`
	_, err = DB.Exec(sql)
	if err != nil {
		return err
	}
	return nil
}
